package com.lnsoft.cac.server.handle.webservice;


import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;

public class I2CAGSyncRspMsg {
    private Element rootElement = null;
    private Document doc = null;
    private Element resultElement = null;

    public I2CAGSyncRspMsg() {
        this.rootElement = new Element("response");
        this.doc = new Document(this.rootElement);
    }

    public void setResultCode(String resultCode) {
        this.resultElement = new Element("result");
        this.rootElement.addContent(this.resultElement);
        this.resultElement.setAttribute("code", resultCode);
    }

    public void setErrorInfo(String errorCode, String errorInfo, String attrName) {
        Element errorElement = null;
        if (errorCode != null) {
            errorElement = new Element("error");
            errorElement.setAttribute("errorcode", errorCode);
            this.resultElement.addContent(errorElement);
        }

        if (errorInfo != null) {
            Element attrElement = new Element("attr");
            attrElement.setAttribute("name", attrName);
            attrElement.setAttribute("value", errorInfo);
            if (errorElement != null) {
                errorElement.addContent(attrElement);
            }
        }

    }

    public Document getDoc() {
        return this.doc;
    }

    public String getMsg() {
        XMLOutputter XMLOut = new XMLOutputter(Format.getPrettyFormat());
        return XMLOut.outputString(this.doc);
    }
}
